package yl.hs.bmipfull.controllers.poundroom;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import yl.hs.bmipfull.controllers.ControllerBase;
import yl.hs.bmipfull.service.laboratory.IPackageInfoService;
import yl.hs.bmipfull.service.production.IBrickShipService;
import yl.hs.bmipfull.viewmodels.PageQuery;
import yl.hs.bmipfull.viewmodels.SubmitModel;
import yl.hs.bmipfull.viewmodels.WebResult;

/**
 * @author 谢东
 * @apiNote
 * @since 2022/12/17 15:03 创建
 */
@Api(value = "磅房Web接口", tags = "过磅管理——商砼过磅操作")
@RequestMapping(value = "/api/BrickWeigh/")
@RestController
public class BrickWeighControllers extends ControllerBase {

    @Autowired
    private IBrickShipService shipService;
    @Autowired
    private IPackageInfoService packageInfoService;
    @ApiOperation(value = "查询产品发货单", notes = "查询产品发货单")
    @RequestMapping(value = "orderList", method = RequestMethod.POST)
    public WebResult queryList(@ApiParam(value = "发货单状态") @RequestParam short state, @ApiParam(value = "返回数据条数") @RequestParam int top, @ApiParam(value = "排序字段") @RequestParam String sort, @ApiParam(value = "查询条件") @RequestParam Object key) {
        try {
            PageQuery pageQuery=new PageQuery();
            pageQuery.getQuery().put("state",state);
            pageQuery.getQuery().put("states",null);
            pageQuery.getQuery().put("sortKey",sort);
            pageQuery.getQuery().put("key",key);
            var result=shipService.queryOrderList(pageQuery,top,0);
            return success("查询成功", result);
        } catch (Exception e) {
            return error(e);
        }
    }
    @ApiOperation(value = "查询产品发货单", notes = "查询产品发货单")
    @RequestMapping(value = "order/{sn}", method = RequestMethod.GET)
    public WebResult findBySN(@ApiParam(value = "查询条件") @PathVariable String sn) {
        try {
            return success("查询成功", shipService.findBySN(sn));
        } catch (Exception e) {
            return error(e);
        }
    }
    @ApiOperation(value = "查询产品发货单", notes = "查询产品发货单")
    @RequestMapping(value = "orderDetail/{sn}", method = RequestMethod.GET)
    public WebResult getDetailByOrderSN(@ApiParam(value = "查询条件") @PathVariable String sn) {
        try {
            return success("查询成功", shipService.getDetailByOrderSN(sn));
        } catch (Exception e) {
            return error(e);
        }
    }
    @ApiOperation(value = "查询产品发货单", notes = "分页查询产品发货单")
    @RequestMapping(value = "/save", method = RequestMethod.PUT)
    public WebResult saveOrder(@ApiParam(value = "提交信息") @RequestBody SubmitModel model){
        try{
            var result = shipService.saveOrder(model);
            return success("ok",result);
        }
        catch (Exception ee){
            return error(ee);
        }
    }
    @ApiOperation(value = "查询包装信息", notes = "查询包装信息")
    @RequestMapping(value = "/fingpackage", method = RequestMethod.GET)
    public WebResult fingPackage(){
        try{
            PageQuery query = new PageQuery();
            var result = packageInfoService.queryList(query);
            return success("ok",result);
        }
        catch (Exception ee){
            return error(ee);
        }
    }
}
